#include "wds_player.h"
#include "wds_sounds.h"


WDSPlayer::Shield::Shield()   :	m_Counter(0),
										m_Rotation(0)
{
	m_BlinkCounter.SetLimit(0.1f);
	m_Sprite.Create("player_shield");	
}

void	WDSPlayer::Shield::Tick(float dt)
{
	m_Sprite.Tick(dt);
	if(m_Counter > 0)
	{
		m_Counter -= dt;
		m_Rotation -= (120 * dt);
		if(m_Rotation < 0.0f)
			m_Rotation += 360.0f;
		if(m_Counter < 2.0f)
		{
			m_BlinkCounter.Tick(dt);
			if(m_BlinkCounter.IsReady())
				m_BlinkCounter.Reset();
		}

		if(m_Counter <= 0)
		{
			WDSSounds::Instance().PlaySoundSFX(WDSSounds::SHIELD_OFF);
		}
	} 
}

void	WDSPlayer::Shield::Render(const math::Vec2& Offset,
									  const math::Vec2& Pos,
									  float Scale)
{
	if(m_Counter > 0)
	{
		if(m_Counter < 2.0f && 
           m_BlinkCounter.GetProgress() < 0.3f)
		{}
		else
		{
			m_Sprite.m_Pos = Pos - Offset;
			m_Sprite.m_Rotation = m_Rotation;
			m_Sprite.m_Size = m_Sprite.m_SizeOriginal * Scale * 0.5f;      		
			m_Sprite.m_Color = ColorfRGBA(1.0f,1.0f,1.0f,0.7f);
			m_Sprite.RenderRotated();
		}
	}
}

void	WDSPlayer::Shield::Activate()
{
	const float SHIELD_MAX_COUNTER = 15.0f;
	m_Counter = SHIELD_MAX_COUNTER;
}

bool	WDSPlayer::Shield::IsActivating()const
{
	if(m_Counter <= 0)
		return false;

	return true;
}

